package com.aaa.behind.controller;


import com.aaa.behind.service.ITbZoneService;
import com.aaa.entity.TbZone;
import com.aaa.util.PageInfo;
import com.aaa.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * <p>
 * 专区 前端控制器
 * </p>
 *
 * @author whj
 * @since 2023-02-01
 */
@RestController
@RequestMapping("/tb-zone")
public class TbZoneController {

    @Autowired
    private ITbZoneService tbZoneService;

    @PostMapping("fuzzySearch")
    public Result fuzzySearch(@ModelAttribute PageInfo pageInfo, TbZone tbZone){
        return new Result(tbZoneService.fuzzySearch(pageInfo,tbZone));
    }

    @PostMapping("updateDisable/{id}/{isDisable}")
    public Result updateDisable(@PathVariable String id,@PathVariable String isDisable){
        TbZone tbZone = new TbZone();
        tbZone.setId(id);
        tbZone.setIsDisable(isDisable);
        return new Result(tbZoneService.updateById(tbZone));
    }

    @GetMapping("removePrefecture/{id}")
    public Result removePrefecture(@PathVariable String id){
        return new Result(tbZoneService.removeById(id));
    }

    @PostMapping("updatePrefecture")
    public Result updatePrefecture(TbZone tbZone){
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String format = dateTimeFormatter.format(now);
        tbZone.setGmtModified(format);
        return new Result(tbZoneService.saveOrUpdate(tbZone));
    }

    @PostMapping("insertPrefecture")
    public Result insertPrefecture(TbZone tbZone){
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String format = dateTimeFormatter.format(now);
        tbZone.setGmtCreate(format);
        tbZone.setIsDeleted(0);
        return new Result(tbZoneService.saveOrUpdate(tbZone));
    }
}

